#include "HitDetection.h"
#include "constants.h"

int getPixelColor(SDL_Surface* lab, int x, int y)
{
    Uint32 *pixels = (Uint32 *)lab->pixels;
    return pixels[ ( y * lab->w ) + x ];
}

int hitDetection(int direction, SDL_Rect girl, SDL_Surface* screen)
{
    //Right 0
    //left 1
    //Up 2
    //Down 3
    int x1 = 0;
    int y1 = 0;
    int x2 = 0;
    int y2 = 0;

    if(direction == 0)
    {
        x1 = girl.x + girl.w;
        y1 = girl.y;
        x2 = x1;
        y2 = girl.y + girl.h;

    }
    else if(direction == 1)
    {
        x1 = girl.x;
        y1 = girl.y;
        x2 = girl.x;
        y2 = girl.y + girl.h;
    }
    else if(direction == 2)
    {
        x1 = girl.x;
        y1 = girl.y;
        x2 = girl.x + girl.w;
        y2 = girl.y;
    }
    else if(direction == 3)
    {
        x1 = girl.x;
        y1 = girl.y + girl.w;
        x2 = girl.x + girl.w;
        y2 = girl.y + girl.h;
    }
    if((getPixelColor(screen, x1, y1) == BLACK_COLOR) || (getPixelColor(screen, x2, y2) == BLACK_COLOR))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
